import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/20 8:55
 * @description 二分查找
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int[] findRightInterval(int[][] intervals) {
        int n = intervals.length;
        int[][] startIn = new int[n][2];
        for (int i = 0; i < n; i++) {
            startIn[i][0] = intervals[i][0];
            startIn[i][1] = i;
        }
        Arrays.sort(startIn, (a, b) -> a[0] - b[0]);
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            int left = 0, right = n - 1, res = -1;
            while (left <= right) {
                int mid = (left + right) / 2;
                if (startIn[mid][0] >= intervals[i][1])  {
                    res = startIn[mid][1];
                    right = mid - 1;
                }else {
                    left = mid + 1;
                }
            }
            ans[i] = res;
        }
        return ans;
    }
}
